(function (aopc) {
    aopc.addExpandPage(849, function (get) {
        const Bridge = get('UtilsCommon', 'Bridge');

        return {
            expandInit() {
                this.isBranchPage = true;
                this.add_share_screen_dialog = this.getProperty('add_share_screen_dialog');
                this.add_share_title = this.getViewProperty(this.add_share_screen_dialog, 'add_share_title');

                this.share_type = this.getProperty('share_type');
                this.share_type.selectValue = 1;
                this.share_type.properties.forEach(p => {
                    p.eventActionName = "setShareType";
                });

                this.share_screen_dialog = this.getProperty('share_screen_dialog');
                this.end_share_screen_dialog = this.getProperty('end_share_screen_dialog');
            },
            componentDidmount() {
                this.showShare();
            },
            setAddShareTitle() {
                if (window.receSharingData) {
                    const { DisplayIndex } = window.receSharingData;
                    this.add_share_title.text = `设备${DisplayIndex}正在共享屏幕中......`;
                }
            },
            setInit() {
                const { SendSharingData, ReceSharingData } = this.visitUser;
                if (!window.sendSharingData) window.sendSharingData = SendSharingData;
                if (!window.receSharingData) window.receSharingData = ReceSharingData;
            },
            closeDialog() {
                Bridge.jsToNative('closeDialog');
            },
            closeShare(isAsync) {
                if (isAsync) window.setTimeout(() => this.closeDialog(), 2000);
                else this.closeDialog();
            },
            showShare() {
                if (window.sendSharingData) {
                    this.end_share_screen_dialog.setIsVisible(true);
                    return;
                }
                else if (window.receSharingData) {
                    const { DisplayIndex, ShareType } = window.receSharingData;
                    if (ShareType === 2) {
                        this.alert(`设备${DisplayIndex}正在共享大屏中`);
                        this.closeShare(true);
                        return
                    }
                    this.setAddShareTitle();
                    this.add_share_screen_dialog.setIsVisible(true);
                }
                else this.showShareDialog();
            },
            addShare() {
                if (!window.receSharingData) {
                    this.alert('共享已结束');
                    this.add_share_screen_dialog.setIsVisible(false);
                    this.closeShare(true);
                    return;
                }
                Bridge.receiveStartShare(window.receSharingData);
            },
            showShareDialog() {
                this.share_screen_dialog.setIsVisible(true);
            },
            setShareType({ property }) {
                this.share_type.properties.forEach((p, i) => {
                    if (property === p) {
                        p.style.backgroundColor = '#ffffff';
                        if (this.theme === 'red') {
                            p.style.border = '2rem solid #EA0000';
                            p.properties[0].spanStyle.color = '#EA0000';
                        }
                        else {
                            p.style.border = '2rem solid #5B93DD';
                            p.properties[0].spanStyle.color = '#5B93DD';
                        }
                        p.style.boxShadow = '0px 17rem 29rem 0px rgba(0,120,251,0.0902)';
                        p.properties[1].setIsVisible(true);
                        this.share_type.selectValue = i + 1;
                    }
                    else {
                        p.style.backgroundColor = 'rgba(255,255,255,0.6)';
                        if (this.theme === 'red') {
                            p.style.border = '2rem solid #FFC8C8';
                        }
                        else {
                            p.style.border = '2rem solid #ADD3F2';
                        }
                        p.style.boxShadow = '';
                        p.properties[0].spanStyle.color = '#2a2a2a';
                        p.properties[1].setIsVisible(false);
                    }
                    p.refresh();
                    p.properties[0].refresh();
                });
            },
            startShare() {
                if (this.isStartShare) return;
                this.isStartShare = true;

                const { selectValue } = this.share_type;

                Bridge.startShare(selectValue, false);
            },
            showEndShareDialog() {
                this.end_share_screen_dialog.setIsVisible(true);
            },
            endShare() {
                if (this.isEndShare) return;
                this.isEndShare = true;

                Bridge.endShare();
            }
        }
    });
})(window.aopc);